﻿/**
* @projectName   cvvision
* @file          IEngine.h
* @brief         引擎接口类
* @author        GuoFeng
* @contact        805305774@qq.com/feng.guo@micro-i.com.cn
* @date          2022-02-09
*/

#ifndef IENGINE_H
#define IENGINE_H

#include <QObject>
#include <QDomDocument>
#include <QImage>
#include <QMap>
#include <opencv2/opencv.hpp>
#include <opencv2/imgproc/types_c.h>

#include "Interface_Global.h"

namespace CVV
{
namespace Interface
{
class IPluginParam;

class INTERFACE_EXPORT IEngine : public QObject
{
    Q_OBJECT
public:
    explicit IEngine(QObject *parent = nullptr);
    virtual ~IEngine() override = 0 ;

    /**
     * @brief initDoc
     * @param doc
     */
    virtual bool initDoc(const QDomDocument &doc, const QString &enginekey = QString()) = 0;

    /**
     * @brief run
     * @param imgHeader 图片头部信息
     * @param picture 图片信息
     */
    virtual bool startRun(const QString & imgHeader,
                          const cv::Mat & picture,
                          const QMap<QString, std::shared_ptr<CVV::Interface::IPluginParam>> &mapInOutParam = QMap<QString, std::shared_ptr<CVV::Interface::IPluginParam>>()) = 0;

    /**
     * @brief getEngineKey
     * @return  m_engineKey
     */
    QString getEngineKey();

signals:
    void sigRunResult(const QString &puginCode,
                      const QString &cellId,
                      std::shared_ptr<CVV::Interface::IPluginParam> pResultOutput = nullptr,
                      bool bSuccess = false);
    /**
     * @brief sigInspectResultReady 执行完方案:数据发送插件调用信号触发把格式化的检测Json数据发送出来
     * @param imgHeader 图片头部信息
     * @param jsonRes  检测缺陷结果
     */
    void sigInspectResultReady(const QString &imgHeader, const QString & jsonRes);
    /**
     * @brief sigRunFinished
     */
    void sigRunFinished(bool bSuccess, float totalRunTime = 0.0);
    /**
     * @brief sigStartNetService 发送启动网络服务信号
     * @param port
     */
    void sigStartNetService(const QString &engineKey, int port);

    /**
     * @brief sigSubprocessRunResult 子流程执行结果
     * @param mapInOutParam
     */
    void sigSubprocessRunResult(const QMap<QString, std::shared_ptr<CVV::Interface::IPluginParam>> &mapInOutParam);

public slots:
    /**
     * @brief startRun 执行
     */
    virtual void slotRun();

protected:
    QDomDocument m_doc;
    QString m_engineKey; //引擎key 配置ID-图片号

private:
    /**
     * @brief run 运行
     * @param doc
     * @return
     */
    virtual bool run(const QString & imgHeader=QString(),
                     const cv::Mat & picture=cv::Mat(),
                     const QMap<QString, std::shared_ptr<CVV::Interface::IPluginParam>> &mapInOutParam = QMap<QString, std::shared_ptr<CVV::Interface::IPluginParam>>()) = 0;

};

}
}

#endif // IENGINE_H
